/**
 * Created by dale on 2017/7/25.
 */
$(document).ready(function () {

    var $type=addressUri.getParam('type');
    var $id=addressUri.getParam('id');

    var title;
    var content='<iframe   src="'+baseUrl+'customer/traceForm?id='+$id+'&type='+$type+'"  style="width: 100%;height:' ;
    if($type==1){
        content+= ' 230px';
        title='跟进情况';
    }else if($type==2){
        content+='410px';
        title='意向情况';
    }else if($type==4){
        content+='230px';
        title='运营等级';
    }
    content+= ';border-style: none;padding: 0px;"  scrolling="yes"   ></iframe>';
    
    $(function () { //加载时间轴
        // $.ajax({
        //     url : baseUrl+'customer/getTraceData',
        //     dataType:'JSON',
        //     type:'Post',
        //     data:{'iCUId':$id,'type':$type},
        //     success:function (data) {
        //
        //         timeLine.loadTimeLine($('#timeWraper'),data['data'],title,data['showDelete'],data['showEdit']);
        //         $('.images').viewer();
        //     },
        //     error:function (result) {
        //         console.log(result);
        //     }
        // })
        xhExtra.ajaxRequest('customer/getTraceData',{'iCUId':$id,'type':$type},{},function (data) {
            timeLine.loadTimeLine($('#timeWraper'),data['data'],title,data['showDelete'],data['showEdit']);
            $('.images').viewer();
        })
    });

    //新建
    $('#new').click(function () {

        window.top.xhTop.showModal({
            title:'新建'+title,
            content:content,
            button:'提交',
            backClose:false
        });
        
    });



    //删除图片ajax
    $('#timeWraper').on('click','[id^=imageDelete_]',function () {
        var iCUTId=$(this).attr("id").split("_")[1];
        var rmId=$(this).attr('id').split('_')[2];
        myWindow.initPopUp({text: '你确定要删除这张图片吗?'},function () {
            xhExtra.ajaxRequest('customer/ajaxDelete',{'iCUTId':iCUTId,'rmId':rmId,'type':$type},{},function (data) {
                timeLine.loadTimeLine($('#timeWraper'),data['data'],title,data['showDelete'],data['showEdit']);
                $('.images').viewer();
            });
        });


    });

    $('#timeWraper').on('click','[id^=fileDelete_]',function () {
        var iCUTId=$(this).attr("id").split("_")[1];
        var rmId=$(this).attr('id').split('_')[2];
        myWindow.initPopUp({text: '你确定要删除这个附件吗?'},function () {
            xhExtra.ajaxRequest('customer/ajaxDelete/fileDelete',{'iCUTId':iCUTId,'rmId':rmId,'type':$type},{},function (data) {
                timeLine.loadTimeLine($('#timeWraper'),data['data'],title,data['showDelete'],data['showEdit']);
            });
        });
    });

    //删除加载数据
    $('#timeWraper').on('click','[id^=delete_]',function () {
        var iCUTId=$(this).attr("id").split("delete_")[1];

        myWindow.initPopUp({},function () {
            xhExtra.ajaxRequest('customer/deleteTraceData',{"iCUTId":iCUTId,'type':$type,'iCUId':$id},{},function (dadta) {
                timeLine.loadTimeLine($('#timeWraper'),data['data'],title,data['showDelete'],data['showEdit']);
                $('.images').viewer();
            });
            // $.ajax({
            //     url : baseUrl+'customer/deleteTraceData',
            //     data : {"iCUTId":iCUTId,'type':$type,'iCUId':$id},
            //     dataType : 'JSON',
            //     type : 'POST',
            //     success:function (data) {
            //         timeLine.loadTimeLine($('#timeWraper'),data['data'],title,data['showDelete'],data['showEdit']);
            //         $('.images').viewer();
            //     },
            //     error:function (result) {
            //         console.log(result);
            //     }
            // });
        });

    });


    //编辑加载数据
    $('#timeWraper').on('click','[id^=edit_]',function () {
       // $('.modal-title')[0].innerHTML="编辑跟进情况";
       // $('.tTrackTime').hide();
        var iCUTId=$(this).attr("id").split("edit_")[1];
        var content='<iframe   src="'+baseUrl+'customer/traceForm?id='+$id+'&type='+$type+'&tid='+iCUTId+'"  style="width: 100%;height:' ;
        if($type==1){
            content+= ' 120px';
        }else if($type==2){
            content+='340px';
        }else if($type==4){
            content+='160px';
        }
        content+= ';border-style: none;padding: 0px;"  scrolling="yes"   ></iframe>';
        window.top.xhTop.showModal({
            title:'编辑'+title,
            content:content,
            button:'提交',
            backClose:false
        });
        
        
    });
});